<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="br.com.seuimovelnamao.model.*, br.com.seuimovelnamao.Util, br.com.seuimovelnamao.TipoPessoa, br.com.seuimovelnamao.StatusImovel, org.springframework.util.StringUtils"%>

<% 
request.setAttribute("semmapa", 1);

Usuario usuario = (Usuario)session.getAttribute("usuario");
String nickname = "";
if(usuario.getTipoPessoa().equals(TipoPessoa.PJ)){
	nickname = usuario.getNomeFantasia();
}else{
	nickname = usuario.getNome();
}
%>

<c:import url="/views/includes/header.jsp" />

<div class="container">
	<div class="content">
		<div style="border-top: #ccc solid 1px" id="divtop">
		
			<p>Olá <b><%=nickname%></b></p>
			
			<% if(TipoPessoa.PJ.equals(usuario.getTipoPessoa())){ %>
				<p><a href="/memberArea/formCadastrarCorretor">Cadastrar Corretor</a></p>
			<% } %>
		
			<table border="0" width="100%" cellpadding="5">
				<tr>
					<th>#</th>
					<th>Categoria</th>
					<th>Intenção</th>
					<th>Endereço</th>
					<th>Cidade</th>
					<th>Estado</th>
					<% if(usuario.getTipoPessoa().equals(TipoPessoa.PJ)){ %>
						<th>Corretor</th>
					<% } %>
					<th>Status</th>
				</tr>
				<!-- percorre os imoveis montando as linhas da tabela -->
				<c:forEach var="imovel" items="${imoveis}" varStatus="cont">
					<tr>
						<td>${cont.count}</td>
						<td>${imovel.categoria}</td>
						<td>${imovel.intencao}</td>
						<td>${imovel.endereco.nomeCompleto}, ${imovel.numero}
							<c:choose><c:when test="${ not empty imovel.complemento }">
								, ${imovel.complemento}
							</c:when></c:choose>
						</td>
						<td>${imovel.endereco.cidade.nome}</td>
						<td>${imovel.endereco.estado.uf}</td>
						<% if(usuario.getTipoPessoa().equals(TipoPessoa.PJ)){ %>
							<td>${imovel.usuario.nome}</td>
						<% } %>
						<td>
							<div class="status">
								<div class="actualstatus">${imovel.status} <img src="/images/arrow_down.png" alt="Alterar Status" style="margin-left:3px;" /></div>
								<div class="select-status">
									<ul>
										<c:set var = "status" value="<%=StatusImovel.ATIVO%>"/>
										<c:choose>
											<c:when test="${imovel.status eq status}">
												<li><a href="/memberArea/ajaxAlterarStatusImovel?id=${imovel.id}&status=<%=StatusImovel.INATIVO%>">Inativar</a></li>
											</c:when>
											<c:otherwise>
												<li><a href="/memberArea/ajaxAlterarStatusImovel?id=${imovel.id}&status=<%=StatusImovel.ATIVO%>">Ativar</a></li>
											</c:otherwise>
										</c:choose>
										<c:set var = "intencao" value="<%=Util.ALUGUEL%>"/>  
										<c:choose>
											<c:when test="${imovel.intencao eq intencao}">
												<li><a href="/memberArea/ajaxAlterarStatusImovel?id=${imovel.id}&status=<%=StatusImovel.ALUGADO%>"><%=StringUtils.capitalize(StatusImovel.ALUGADO)%></a></li>
											</c:when>
											<c:otherwise>
												<li><a href="/memberArea/ajaxAlterarStatusImovel?id=${imovel.id}&status=<%=StatusImovel.VENDIDO%>"><%=StringUtils.capitalize(StatusImovel.VENDIDO)%></a></li>
											</c:otherwise>
										</c:choose>
									</ul>
								</div>
							</div>
						</td>
					</tr>
				</c:forEach>
			</table>
		
		</div>
</body>
</html>